﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DWEIP.Models;
using DataWin.Core.Model;
using DataWin.Core.Util;

namespace DWEIP.BLL
{
    public class AccountBLL : BasicBLL
    {
        public SysUser Login(string username, string pwd)
        {
            Table _tam05 = new Table("tam05");
            _tam05.SQL.Value = @"
SELECT tam05.* FROM tam05 where ae01=@user and ae04=@pass";
            _tam05.Params.Clear();
            _tam05.Params.Add("user", new Data(username));
            _tam05.Params.Add("pass", new Data(pwd));
            BLLSession.Load(_tam05);

            if (_tam05.Count > 0)
            {
                foreach (IRow Row in _tam05)
                {
                    SysUser sysUser = new SysUser();
                    sysUser.Id = Row["ae01"].AsString;
                    sysUser.UserName = Row["ae03"].AsString;
                    sysUser.Password = Row["ae04"].AsString;
                    sysUser.TrueName = Row["ae02"].AsString;
                    sysUser.Card = "";
                    sysUser.MobileNumber = Row["ae_13"].AsString;
                    sysUser.PhoneNumber = Row["ae_12"].AsString;
                    sysUser.QQ = "";
                    sysUser.EmailAddress = Row["ae_10"].AsString;
                    sysUser.OtherContact = "";
                    sysUser.Province = "";
                    sysUser.City = "";
                    sysUser.Village = "";
                    sysUser.Address = "";
                    sysUser.State = true;
                    sysUser.CreateTime = Row["create_date"].AsDateTime;
                    sysUser.CreatePerson = Row["create_user"].AsString;
                    sysUser.Sex = "";
                    sysUser.Birthday = (new Data("19800101")).AsDateTime;
                    sysUser.JoinDate = (new Data("20000101")).AsDateTime;
                    sysUser.Marital = "";
                    sysUser.Political = "";
                    sysUser.Nationality = "";
                    sysUser.Native = "";
                    sysUser.School = "";
                    sysUser.Professional = "";
                    sysUser.Degree = "";
                    sysUser.DepId = Row["ae05"].AsString;
                    sysUser.PosId = "";
                    sysUser.Expertise = "";
                    sysUser.JobState = true;
                    sysUser.Photo = "";
                    sysUser.Attach = "";
                    sysUser.Lead = "";
                    sysUser.LeadName = "";
                    sysUser.IsSelLead = true;
                    sysUser.IsReportCalendar = true;
                    sysUser.IsSecretary = false;

                    return sysUser;
                }
            }
            return null;
        }
    }
}
